package com.test.springquickstart.exception;

import jakarta.validation.ConstraintViolationException;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ConstraintViolationException.class)
    public String handleValidationException(ConstraintViolationException e) {
        e.printStackTrace();
        return StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "process error";
    }
}
